import httpRequest from "@/utils/http-request.js";

<#assign entityBaseColumns = ["id", "created_at", "created_by", "created_from", "updated_at", "updated_by", "deleted"]>

/**
 * 新增
<#list columns as column>
<#if !entityBaseColumns?seq_contains(column.columnName)>
 * @param ${column.columnNameCamel}
</#if>
</#list>
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const add = (
    {
<#list columns as column>
<#if !entityBaseColumns?seq_contains(column.columnName)>
        ${column.columnNameCamel},
</#if>
</#list>
    }
) => {
    return httpRequest.post("/v1/${tablePrefix}/${mappingBase}", {
<#list columns as column>
<#if !entityBaseColumns?seq_contains(column.columnName)>
        ${column.columnNameCamel},
</#if>
</#list>
    });
}

/**
 * 根据ID删除
 * @param id
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const deleteById = (id) => {
    return httpRequest.delete(`/v1/${tablePrefix}/${mappingBase}/<#noparse>${id}</#noparse>`);
}


/**
 * 修改
 * @param id
<#list columns as column>
<#if !entityBaseColumns?seq_contains(column.columnName)>
 * @param ${column.columnNameCamel}
</#if>
</#list>
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const modifyById = (
    id,
    {
<#list columns as column>
<#if !entityBaseColumns?seq_contains(column.columnName)>
        ${column.columnNameCamel},
</#if>
</#list>
    }
) => {
    return httpRequest.put(`/v1/${tablePrefix}/${mappingBase}/<#noparse>${id}</#noparse>`, {
<#list columns as column>
<#if !entityBaseColumns?seq_contains(column.columnName)>
        ${column.columnNameCamel},
</#if>
</#list>
    });
}

/**
 * 详情
 * @param id
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const detailById = (id) => {
    return httpRequest.get(`/v1/${tablePrefix}/${mappingBase}/detail/<#noparse>${id}</#noparse>`);
}

/**
 * 分页查询
 * @param page
 * @param size
 * @returns {*}
 */
export const page = (page, size) => {
    return httpRequest.get(`/v1/${tablePrefix}/${mappingBase}/page/<#noparse>${page}/${size}</#noparse>`);
}
